package com.tmpt.utils;
 
import java.math.BigDecimal;

public class FenAndYuan {
	//'分'转化成'元' 保留2位有效小数  参数long
	public static double fen2yuan(long fen){
		//.out.println("-1---");
		BigDecimal yuan = new BigDecimal(fen/100.0);
		yuan = yuan.setScale(2, BigDecimal.ROUND_HALF_UP);
		return yuan.doubleValue();
	} 
	public static double feng2yuan(long fen){
		return fen2yuan(fen);
	}
	//'分'转化成'元' 保留2位有效小数  参数double
	public static double fen2yuan(double fen){
		BigDecimal yuan = new BigDecimal(fen/100.0);
		yuan = yuan.setScale(2, BigDecimal.ROUND_HALF_UP);
		return yuan.doubleValue();
	}
	//'分'转化成'元' 保留2位有效小数  参数String
	public static double fen2yuan(Object fen){
		if(fen==null || fen.equals("")){return 0;}
		BigDecimal yuan = new BigDecimal(Long.parseLong(fen.toString())/100.0);
		yuan = yuan.setScale(2, BigDecimal.ROUND_HALF_UP);
		return yuan.doubleValue();
	} 

	//'分'转化成'元' 保留2位有效小数  参数String
	public static String fen2yuanStr(Object fen){
		if(fen==null || fen.equals("")){return "";}
		BigDecimal yuan = new BigDecimal(Long.parseLong(fen.toString())/100.0);
		yuan = yuan.setScale(2, BigDecimal.ROUND_HALF_UP);
		return yuan.toString();
	} 
	public static String feng2yuanStr(Object fen){
		return fen2yuanStr(fen);
	}
	//'元' convert to '分'
	public static String yuan2fenStr(String yuan){
		String fen = String.valueOf(FenAndYuan.yuan2fenLng(yuan));
		return fen;
	}
	public static long yuan2fenLng(double yuan){
		return FenAndYuan.yuan2fenLng(String.valueOf(yuan));
	}
	public static long yuan2fenLng(String yuan){
		if(yuan==null || yuan.trim().equals(""))return 0;
		BigDecimal yuanBD = new BigDecimal(yuan);
		BigDecimal fenDB = yuanBD.multiply(new BigDecimal(100));
		long fenLong = fenDB.longValue();
		return fenLong;
	}
	
	public static String yuan2Wan(String yuan){
		String wan = "";
		if(yuan==null || yuan.trim().equals(""))return wan;
		BigDecimal yuanBD = new BigDecimal(yuan);
		BigDecimal wanBD = yuanBD.divide(new BigDecimal(10000));
		wan = wanBD.toString();
		return wan+"万";
	}
	
	public static void main(String[] args){
		String wan = FenAndYuan.yuan2Wan("5108012");
		//.out.println(wan);
		//String ss = ""+fenAndYuan.yuan2fenLng("");
		////.out.println(ss);
		/*
		String yuan = "17398.1";
		//.out.println(FenAndYuan.yuan2fenStr(yuan));
		//.out.println(Double.valueOf(yuan)*100);
		
		String fen = "1739810";
		//.out.println(Long.parseLong(fen)/100.0);
		*/
	}
}
